<hr />
<form id="frec" action="" method="get">
    <input type="hidden" name="id" value="" />
    <input type="hidden" name="action" value="edit" />
    <input type="hidden" name="what" value="item" />
    <p>
        <label>Edit database record:
            <input id="recsel" /></label>
        <input type="submit" value="Edit" />
        or
        <a href="?action=edit&amp;what=item&amp;id=-1">New Record</a>
<?php if (isset($_GET['last'])) { ?>
            or <a href="?action=edit&amp;what=item&amp;id=<?php echo $_GET['last'] ?>">Last Edited</a>
<?php } ?>

        <br />
    </p>
</form>
<?php if(SFX_ENABLED){ ?>
<form id="fsfx" action="" method="get">
    <input type="hidden" name="id" value="" />
    <input type="hidden" name="action" value="edit" />
    <input type="hidden" name="what" value="sfx" />
    <p><label>SFX records:
            <input id="sfxsel" /></label>
        <input type="submit" value="Edit" />
<?php if (isset($_GET['lastsfx'])) { ?>
            or <a href="?action=edit&amp;what=sfx&amp;id=<?php echo $_GET['lastsfx'] ?>">Last Edited</a>
<?php } ?>
    </p>
</form>
<?php } ?>
<script type="text/javascript">
var wsx;
$(
	function(){
		$('input#recsel').autocomplete({
			source:function(request,response){
				$.ajax({
					url:"<?php echo WT_URL?>search.php",
					dataType:"jsonp",
					data:{like:request.term,type:'local'},
					success:
						function(data){
							response(data);
						}
				});
			},
			open: function() {
				$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
			},
			close: function() {
				$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
			},
			delay:0,
			minLength:0,
			focus:function(event,ui){
				return false;
			},
			select:function(event,ui){
				$('#recsel').attr('value',ui.item.label);
				$('#frec input[name=id]').attr('value',ui.item.value);
				$('#frec').eq(0).submit();
				return false;
			}
		});
		$('input#sfxsel').autocomplete({
			source:function(request,response){
				$.ajax({
					url:"<?php echo WT_URL?>search.php",
					dataType:"jsonp",
					data:{like:request.term,type:'sfx'},
					success:
						function(data){
							response(data);
						}
				});
			},
			open: function() {
				$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
			},
			close: function() {
				$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
			},
			delay:0,
			minLength:0,
			focus:function(event,ui){
				return false;
			},
			select:function(event,ui){
				$('#sfxsel').attr('value',ui.item.label);
				$('#fsfx input[name=id]').attr('value',ui.item.value);
				$('#fsfx').eq(0).submit();
				return false;
			}
		});
	}
);

    var popwin=false;

    function redirect(q,pop){
        $('.dropdown').hide();
        if(!pop){
            document.location.href='?'+q;
        }else{
            var url='<?php echo WT_URL; ?>'+'?'+q;
            popwin=window.open(url,'wt_pop','height=600,width=800,scrollbars=yes,resizable=yes,dependent=yes,fullscreen=no,alwaysRaised=no');
        }
    }
</script>
<h3>EZproxy configuration</h3>
<ul>
    <li>
        <?php
        $d = "";
        $t = "";
        if (!file_exists(EZCONFIG)) {
            echo('(No current configuration)');
        } else {
            echo('<a target="_blank" href="?action=view&amp;file=current">View Current Configuration</a>');
        }
        ?>
    </li>
    <li>
        <a href="?action=ezgen">Generate New Configuration</a>
    </li>
    <li>
        <?php
        if (!file_exists(EZCONFIG_DIR . 'config.txt')) {
            echo('(No current configuration)');
        } else {
            echo('<a target="_blank" href="?action=view&amp;file=generated">View Last Generated Configuration</a>');
        }
        ?>
    </li>
    <li>
        <a href="?action=commit">Enable Last Generated Configuration</a>
    </li>
    <li>
        <a href="?action=restore&amp;dir=config">Restore from Backup</a>
    </li>
</ul>
<?php if (SFX_ENABLED) { ?>
            <h3>SFX</h3>
            <ul>
                <li>
        <?php
            $d = "";
            $t = "";
            if (!file_exists(SFX_DIR . 'sfx.cfg.txt')) {
                echo('(No SFX Include file exists)');
            } else {
                echo('<a target="_blank" href="?action=view&amp;file=sfx">View SFX Include File</a>');
            }
        ?>
        </li>
        <li>
        <?php
            $lastsfx = 'never';
            if (file_exists(SFX_DIR . '/sfx.cfg.txt')) {
                $lastsfx = date('Y-m-d g:i:s a', filemtime(SFX_DIR . 'sfx.cfg.txt'));
            }
        ?>
            <a target="_blank" href="?action=sfxgen">Run SFX Import Manually</a> (last run <?php echo $lastsfx; ?>)
        </li>
    </ul>
<?php } ?>
<?php if ($_SERVER['PHP_AUTH_USER'] != LIMITED_USER) { ?>
            <h3>Header/Access</h3>
            <ul>
                <li><a href="?action=edit&amp;what=txt&amp;file=header">Edit Configuration Header</a></li>
                <li><a href="?action=edit&amp;what=txt&amp;file=auto">Edit Access Restrictions</a></li>
                <li><a href="?action=restore&amp;dir=txt">Restore from Backup</a></li>
            </ul>
<?php } ?>
        <h3>Restart EZproxy</h3>
        <button onclick="return function(){if(confirm('Are you sure?')){redirect('action=restartez',false);}else{return false;}}();">Restart EZproxy</button>
        <button onclick="return function(){if(confirm('Are you sure?')){redirect('action=tamale_lite',false);}else{return false;}}();">Generate Local/Enable/Restart</button>
<?php if (SFX_ENABLED) { ?>
            <button onclick="return function(){if(confirm('Are you sure?')){redirect('action=tamale',false);}else{return false;}}();">Generate Local+SFX/Enable/Restart</button>
<?php } ?>